<template>
  <div class="body">
    <div class="header">
      <img
        @click="nav({goods_id:11816})"
        src="../../assets/img/egg/nut@2x.png"
        class="one"
        alt=""
      >
      <img
        @click="nav({goods_id:11936})"
        src="../../assets/img/egg/nut@2x.png"
        class="two"
        alt=""
      >
      <img
        @click="nav({goods_id:4806})"
        src="../../assets/img/egg/nut@2x.png"
        class="three"
        alt=""
      >
      <img
        @click="nav({goods_id:11440})"
        src="../../assets/img/egg/nut@2x.png"
        class="four"
        alt=""
      >
      <img
        @click="nav({goods_id:10849})"
        src="../../assets/img/egg/nut@2x.png"
        class="five"
        alt=""
      >
    </div>
    <!-- 置顶 -->
    <div
      class="totop"
      id="totop"
      @click="backTop"
      v-show="btnFlag"
    >
      <!-- <i class="iconfont icon-zhiding"></i> -->
    </div>
  </div>
</template>

<script>
import bridge from '../../js/js1'
import { Frequency, doDraw, Win, Luckdraw } from '@/api/index'
import { share } from '../../js/public'
import { getSystem, openApp, getUrlQuery, parseKeyValue } from '../../js/js'
// import Vconsole from 'vconsole'
// const vConsole = new Vconsole()
export default {
  // 组件名称
  name: 'egg',
  // 局部注册的组件
  components: {
  },
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
    return {
      system: getSystem(),
      show: false,
      btnFlag: false,
      share: true,
    }
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  destroyed () {
    window.removeEventListener('scroll', this.scrollToTop);
  },
  // 生命周期钩子   注：没用到的钩子请自行删除
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  created () {
    this.system = getSystem()
    // 调用获取次数接口 获取剩余 分享次数 和 游戏次数
  },
  /**
  * el 被新创建的 vm.el 替换，并挂载到实例上去之后调用该钩子。
  * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.el 也在文档内。
  */
  mounted () {
    this.toph()
    window.addEventListener('scroll', this.scrollToTop)
    share({
      title: '媛福达美味蛋黄酥，新品上市',
      desc: '媛福达蛋黄酥，四层口感绵软酥香，抄底价29.8元/2盒',
      imgUrl: 'https://download.yuanfuda933.com/h5/images/egg.png',
      shareUrl: 'https://download.yuanfuda933.com/h5/other2.html#/egg',
      share: this.share,
    })
  },
  // 组件方法
  methods: {
    toph () {
      if (this.system.wechat) {
        this.show = true
        return false
      } else {
        this.show = false
      }
    },
    Gone () {
      if (this.system.iOS) {
        this.href('https://itunes.apple.com/cn/app/id1542709823?mt=8')
      } else if (this.system.android) {
        window.location.href = 'https://yuanfuda933.oss-cn-zhangjiakou.aliyuncs.com/yfdMall_1_v1.0.1.apk'
      }
    },
    // 跳转下载
    nav (item) {
      if (this.system.wechat) {
        this.show = true
        return false
      } else {
        this.show = false
      }
      if (!this.system.iOS9 && !this.system.android) {
        this.href('https://itunes.apple.com/cn/app/id1542709823?mt=8')
        return false
      }
      console.log(item);
      if (this.system.android) {
        openApp({
          query: { spuId: item.goods_id }
        })
      }
      if (this.system.iOS) this.href('https://itunes.apple.com/cn/app/id1542709823?mt=8')

    },
    // 点击图片回到顶部方法，加计时器是为了过渡顺滑
    backTop () {
      const that = this
      let timer = setInterval(() => {
        let ispeed = Math.floor(-that.scrollTop / 5)
        document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed
        if (that.scrollTop === 0) {
          clearInterval(timer)
        }
      }, 16)
    },
    // 为了计算距离顶部的高度，当高度大于60显示回顶部图标，小于60则隐藏
    scrollToTop () {
      const that = this
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      that.scrollTop = scrollTop
      // console.log(that.scrollTop);
      if (that.scrollTop > 800) {
        that.btnFlag = true
      } else {
        that.btnFlag = false
      }
    },
    // 跳转下载
    nav (item) {
      console.log(item.goods_id);
      // window.locaition.href = 'http://yuanfuda933.oss-cn-zhangjiakou.aliyuncs.com/yfdMall_1_v1.0.1.apk?squId=' + 'item.goods._id'
      window.location.href = 'yfd://yfdmall:8080/goodsDetail?spuId=' + item.goods_id
    },
    href (uri, blank = true) {
      const a = document.createElement('a')
      a.style.display = 'none'
      a.href = uri
      if (blank) a.setAttribute('target', '_blank')
      document.body.appendChild(a)
      a.click()
      setTimeout(t => {
        document.body.removeChild(a)
      }, 0)
    },
  }
}
</script>

<style scoped lang="less">
.body {
  overflow: hidden;
  min-width: 320px;
  max-width: 750px;
  width: 10rem;
  // height: 57.28rem;
  // background: #6704a6;
  margin: 0 auto;
  line-height: 1.5;
  font-family: Arial, Helvetica;
  .totop {
    position: fixed;
    width: 1.2rem; /* 40/16 */
    height: 1.2rem;
    border-radius: 1.25rem /* 20/16 */;
    opacity: 0.8;
    background: url("../../assets/ding.png") no-repeat;
    background-size: contain;
    box-shadow: 0 1px 5px 0 #e0e0e0;
    right: 0.125rem; /* 18/16 */
    bottom: 3rem; /* 64/16 */
    z-index: 1100;
    -webkit-transition: opacity 0.5s;
    transition: opacity 0.5s;
  }
  @keyframes mymove {
    0% {
      transform: scale(1); /*开始为原始大小*/
    }
    25% {
      transform: scale(1.1); /*放大1.1倍*/
    }
    50% {
      transform: scale(1);
    }
    75% {
      transform: scale(1.1);
    }
  }
  @-webkit-keyframes mymove /*Safari and Chrome*/ {
    0% {
      transform: scale(1); /*开始为原始大小*/
    }
    25% {
      transform: scale(1.1); /*放大1.1倍*/
    }
    50% {
      transform: scale(1);
    }
    75% {
      transform: scale(1.1);
    }
  }
  .header {
    width: 10rem;
    height: 95.546667rem;
    background: url("../../assets/img/egg/pic@2x.png") no-repeat;
    background-size: contain;
    position: relative;
    img {
      width: 2.586667rem;
      height: 0.866667rem;
      animation: mymove 2s infinite;
      -webkit-animation: mymove 2s infinite; /*Safari and Chrome*/
      animation-direction: alternate; /*轮流反向播放动画。*/
      animation-timing-function: ease-in-out; /*动画的速度曲线*/
      /* Safari 和 Chrome */
      -webkit-animation: mymove 2s infinite;
      -webkit-animation-direction: alternate; /*轮流反向播放动画。*/
    }
    .one {
      position: absolute;
      top: 19.2%;
      left: 61%;
    }
    .two {
      position: absolute;
      top: 23.4%;
      left: 14%;
    }
    .three {
      position: absolute;
      top: 52%;
      left: 57%;
    }
    .four {
      position: absolute;
      top: 58.1%;
      left: 17%;
    }
    .five {
      position: absolute;
      top: 64.3%;
      left: 58%;
    }
  }
  .banner {
    z-index: 99;
    position: fixed;
    top: 0%;
    width: 10rem;
    height: 2.28rem;
    background: #000000;
    display: flex;
    .imgone {
      display: block;
      margin: auto 0.293333rem;
      width: 0.586667rem;
      height: 0.586667rem;
    }
    .imgtwo {
      display: block;
      margin: auto 0.266667rem;
      width: 1.28rem;
      height: 1.28rem;
    }
    .spanone {
      margin: auto 0.066667rem;
      width: 3.2rem;
      height: 1.453333rem;
      font-size: 0.426667rem;
      color: #ffffff;
      .spantwo {
        font-size: 0.32rem;
        font-size: #9b9b9b;
        color: #9b9b9b;
      }
    }
    .btn {
      width: 1.633333rem;
      height: 0.906667rem;
      background: #ea0462;
      border-radius: 0.133333rem;
      font-size: 0.426667rem;
      color: #ffffff;
      text-align: center;
      line-height: 0.906667rem;
      margin: auto 0.1rem;
    }
  }
}
</style>
